let api = [];
const apiDocListSize = 1
api.push({
    name: 'default',
    order: '1',
    list: []
})
api[0].list.push({
    alias: 'e79656c670c5f274ff1f8b7f4f5a9fd6',
    order: '1',
    link: '分体空调',
    desc: '分体空调',
    list: []
})
api[0].list[0].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/air/getAreaAcdInfo',
    desc: '获取区域和子区域空调状况信息',
});
api[0].list[0].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/air/multiSetAreaAcd',
    desc: '批量操作区域下的空调',
});
api[0].list[0].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/air/setAcd',
    desc: '操作空调（手动实时）',
});
api[0].list[0].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/air/setAcdPlan',
    desc: '设置空调策略方案',
});
api[0].list[0].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:8080/air/delAcdPlan',
    desc: '移除空调上的策略方案',
});
api[0].list[0].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:8080/air/multiSetAreaAcdPlan',
    desc: '批量设置区域下空调策略方案',
});
api[0].list[0].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://localhost:8080/air/setAcdPlanSwitch',
    desc: '设置空调的策略开关',
});
api[0].list[0].list.push({
    order: '8',
    deprecated: 'false',
    url: 'http://localhost:8080/air/refreshAcdTime',
    desc: '空调校对时间',
});
api[0].list[0].list.push({
    order: '9',
    deprecated: 'false',
    url: 'http://localhost:8080/air/setAcdPolicyData',
    desc: '设置分体空调策略初始参数',
});
api[0].list[0].list.push({
    order: '10',
    deprecated: 'false',
    url: 'http://localhost:8080/air/setAcdPowerSwitch',
    desc: '设置分体空调继电器开关',
});
api[0].list[0].list.push({
    order: '11',
    deprecated: 'false',
    url: 'http://localhost:8080/air/setBeeWarn',
    desc: '设置蜂鸣预警器',
});
api[0].list.push({
    alias: 'f02afebc6fd9f626570f3fb70e5388e4',
    order: '2',
    link: '分体空调策略',
    desc: '分体空调策略',
    list: []
})
api[0].list[1].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/air/policy/list',
    desc: '获取脱机策略列表',
});
api[0].list[1].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/air/policy/getAcdPlanById',
    desc: '查看脱机策略详情',
});
api[0].list[1].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/air/policy/addNew',
    desc: '新增脱机策略',
});
api[0].list[1].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/air/policy/del',
    desc: '删除脱机策略',
});
api[0].list.push({
    alias: 'ccb2088b5cb38db4386da54a464ad241',
    order: '3',
    link: '分析模块',
    desc: '分析模块',
    list: []
})
api[0].list[2].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/analysis/getAreaEcp',
    desc: '获取区域能耗',
});
api[0].list[2].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/analysis/getAreaEcpCompare',
    desc: '获取区域能耗对比',
});
api[0].list[2].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/analysis/getAreaFengGuPing',
    desc: '获取区域峰谷平',
});
api[0].list[2].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/analysis/getDeviceEcp',
    desc: '获取区域设备能耗',
});
api[0].list[2].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:8080/analysis/getDeviceEcpCompare',
    desc: '获取区域设备能耗对比',
});
api[0].list[2].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:8080/analysis/getDeviceFengGuPing',
    desc: '获取区域设备峰谷平',
});
api[0].list.push({
    alias: '2c62c5b2481ed8b5118e4bbe24a98aef',
    order: '4',
    link: '看板',
    desc: '看板',
    list: []
})
api[0].list[3].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/board/getEnergyStatistics',
    desc: '能耗概貌',
});
api[0].list[3].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/board/getEnergyTrend',
    desc: '能耗趋势',
});
api[0].list.push({
    alias: '7111afde44bf5d792a5bad72fa6ab6f3',
    order: '5',
    link: '通用',
    desc: '通用',
    list: []
})
api[0].list[4].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getCtlAreaByPid',
    desc: '根据父id获取有控制设备的区域',
});
api[0].list[4].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getEnergyAreaByPid',
    desc: '根据父区域id获取有权限的子区域',
});
api[0].list[4].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getEnergyByAreaNo',
    desc: '根据区域编号获取能源列表',
});
api[0].list[4].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getTableDeviceByAreaNo',
    desc: '根据区域编号获取表具设备列表',
});
api[0].list[4].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getPointList',
    desc: '获取所有计量点列表',
});
api[0].list[4].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getTransformerList',
    desc: '获取变压器列表',
});
api[0].list[4].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://localhost:8080/common/getElectricPoint',
    desc: '用电计量点',
});
api[0].list.push({
    alias: '362ec8ba6a9d40104a96c5f0bd07d4ce',
    order: '6',
    link: '控制相关',
    desc: '控制相关',
    list: []
})
api[0].list[5].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/ctl/getAreaCtlInfo',
    desc: '区域控制设备信息',
});
api[0].list.push({
    alias: '247cf52ac0af0f49ce32ff18c2115519',
    order: '7',
    link: '数据记录模块',
    desc: '数据记录模块',
    list: []
})
api[0].list[6].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/log/getCurParamData',
    desc: '获取设备当前参数数据',
});
api[0].list.push({
    alias: '58e795bc6bd7e9bf2b948567d4d9caba',
    order: '8',
    link: '主页相关',
    desc: '主页相关',
    list: []
})
api[0].list[7].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/home/rootArea',
    desc: '获取总区域信息',
});
api[0].list[7].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/home/totalElectric',
    desc: '总区域用电量',
});
api[0].list[7].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/home/energyCpSta',
    desc: '能源资源统计分析',
});
api[0].list[7].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/home/energyUsageAmount',
    desc: '分类能源消耗量',
});
api[0].list[7].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:8080/home/areaEnergyCp',
    desc: '重点区域综合能耗',
});
api[0].list[7].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:8080/home/energyTargetPrs',
    desc: '能源资源指标进度',
});
api[0].list[7].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://localhost:8080/home/totalEnergyCp',
    desc: '综合能源消耗量（年）',
});
api[0].list[7].list.push({
    order: '8',
    deprecated: 'false',
    url: 'http://localhost:8080/home/areaRank',
    desc: '各区域本月能耗排名',
});
api[0].list[7].list.push({
    order: '9',
    deprecated: 'false',
    url: 'http://localhost:8080/home/yearOnYear',
    desc: '能耗同期对比',
});
api[0].list[7].list.push({
    order: '10',
    deprecated: 'false',
    url: 'http://localhost:8080/home/getHomeFunc',
    desc: '获取模块',
});
api[0].list[7].list.push({
    order: '11',
    deprecated: 'false',
    url: 'http://localhost:8080/home/getFuncByHomeFunc',
    desc: '根据模块获取菜单',
});
api[0].list.push({
    alias: 'a684aae12690521aaf8e397ced8b1192',
    order: '9',
    link: '照明',
    desc: '照明',
    list: []
})
api[0].list[8].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/light/getAreaLightInfo',
    desc: '',
});
api[0].list[8].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/light/multiSetAreaLight',
    desc: '批量操作区域下的照明',
});
api[0].list[8].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/light/setLight',
    desc: '操作照明（手动实时）',
});
api[0].list[8].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/light/setLightPlan',
    desc: '设置照明策略方案',
});
api[0].list[8].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:8080/light/delLightPlan',
    desc: '移除照明上的策略方案',
});
api[0].list[8].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:8080/light/multiSetAreaLightPlan',
    desc: '批量设置区域下照明策略方案',
});
api[0].list.push({
    alias: 'e10444da889624ecc0ba870855fc6098',
    order: '10',
    link: '照明策略',
    desc: '照明策略',
    list: []
})
api[0].list[9].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/light/policy/list',
    desc: '',
});
api[0].list[9].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/light/policy/getLightPlanById',
    desc: '',
});
api[0].list[9].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/light/policy/addNew',
    desc: '',
});
api[0].list[9].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/light/policy/del',
    desc: '',
});
api[0].list.push({
    alias: '2db29075135cb44040cb814ec8ef5949',
    order: '11',
    link: '登录相关',
    desc: '登录相关',
    list: []
})
api[0].list[10].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/login/checkLogin',
    desc: '登录',
});
api[0].list[10].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/login/getUserInfo',
    desc: '获取登录用户信息',
});
api[0].list[10].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/login/logout',
    desc: '登出',
});
api[0].list.push({
    alias: '7b28cb58c3400a93c8a968c90f20980c',
    order: '12',
    link: '实时监测',
    desc: '实时监测',
    list: []
})
api[0].list[11].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/monitor/AreaPointState',
    desc: '区域计量点状态监测',
});
api[0].list.push({
    alias: '609a9aa995d78c9d2188ba9292ae8e95',
    order: '13',
    link: '电能质量',
    desc: '电能质量',
    list: []
})
api[0].list[12].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/power/getPowerFactor',
    desc: '功率因数',
});
api[0].list[12].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:8080/power/getElectricCurrentVoltage',
    desc: '电流电压',
});
api[0].list[12].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:8080/power/getElectricLoad',
    desc: '电力负荷',
});
api[0].list[12].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:8080/power/getPowerRatio',
    desc: '功率占比',
});
api[0].list.push({
    alias: '9ec32af426fcca6983f23e74d69a93df',
    order: '14',
    link: '报表中心',
    desc: '报表中心',
    list: []
})
api[0].list[13].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/report/getPointReport',
    desc: '点位底数报表',
});
api[0].list.push({
    alias: '42d15f6d15f0925643654c65330cc094',
    order: '15',
    link: '系统相关',
    desc: '系统相关',
    list: []
})
api[0].list[14].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:8080/sys/getAppVersion',
    desc: '获取app版本号',
});
api[0].list.push({
    alias: 'error',
    order: '16',
    link: 'error_code_list',
    desc: '错误码列表',
    list: []
})
api[0].list.push({
    alias: 'dict',
    order: '17',
    link: 'dict_list',
    desc: '数据字典',
    list: []
})
api[0].list[16].list.push({
    order: '1',
    deprecated: 'false',
    url: '',
    desc: '时间类型',
});
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code === 13) {
        const search = document.getElementById('search');
        const searchValue = search.value.toLocaleLowerCase();

        let searchGroup = [];
        for (let i = 0; i < api.length; i++) {

            let apiGroup = api[i];

            let searchArr = [];
            for (let i = 0; i < apiGroup.list.length; i++) {
                let apiData = apiGroup.list[i];
                const desc = apiData.desc;
                if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                    searchArr.push({
                        order: apiData.order,
                        desc: apiData.desc,
                        link: apiData.link,
                        list: apiData.list
                    });
                } else {
                    let methodList = apiData.list || [];
                    let methodListTemp = [];
                    for (let j = 0; j < methodList.length; j++) {
                        const methodData = methodList[j];
                        const methodDesc = methodData.desc;
                        if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                            methodListTemp.push(methodData);
                            break;
                        }
                    }
                    if (methodListTemp.length > 0) {
                        const data = {
                            order: apiData.order,
                            desc: apiData.desc,
                            link: apiData.link,
                            list: methodListTemp
                        };
                        searchArr.push(data);
                    }
                }
            }
            if (apiGroup.name.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchGroup.push({
                    name: apiGroup.name,
                    order: apiGroup.order,
                    list: searchArr
                });
                continue;
            }
            if (searchArr.length === 0) {
                continue;
            }
            searchGroup.push({
                name: apiGroup.name,
                order: apiGroup.order,
                list: searchArr
            });
        }
        let html;
        if (searchValue === '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchGroup,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            let $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiGroups, liClass, display) {
    let html = "";
    if (apiGroups.length > 0) {
        if (apiDocListSize === 1) {
            let apiData = apiGroups[0].list;
            let order = apiGroups[0].order;
            for (let j = 0; j < apiData.length; j++) {
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_'+order+'_'+apiData[j].order+'_' + apiData[j].link + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                html += '<ul class="sectlevel2" style="'+display+'">';
                let doc = apiData[j].list;
                for (let m = 0; m < doc.length; m++) {
                    let spanString;
                    if (doc[m].deprecated === 'true') {
                        spanString='<span class="line-through">';
                    } else {
                        spanString='<span>';
                    }
                    html += '<li><a href="#_'+order+'_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                }
                html += '</ul>';
                html += '</li>';
            }
        } else {
            for (let i = 0; i < apiGroups.length; i++) {
                let apiGroup = apiGroups[i];
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_'+apiGroup.order+'_' + apiGroup.name + '">' + apiGroup.order + '.&nbsp;' + apiGroup.name + '</a>';
                html += '<ul class="sectlevel1">';

                let apiData = apiGroup.list;
                for (let j = 0; j < apiData.length; j++) {
                    html += '<li class="'+liClass+'">';
                    html += '<a class="dd" href="#_'+apiGroup.order+'_'+ apiData[j].order + '_'+ apiData[j].link + '">' +apiGroup.order+'.'+ apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                    html += '<ul class="sectlevel2" style="'+display+'">';
                    let doc = apiData[j].list;
                    for (let m = 0; m < doc.length; m++) {
                       let spanString;
                       if (doc[m].deprecated === 'true') {
                           spanString='<span class="line-through">';
                       } else {
                           spanString='<span>';
                       }
                       html += '<li><a href="#_'+apiGroup.order+'_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">'+apiGroup.order+'.' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                   }
                    html += '</ul>';
                    html += '</li>';
                }

                html += '</ul>';
                html += '</li>';
            }
        }
    }
    return html;
}